//
//  MagazineListTabView.m
//  YZZX
//
//  Created by Easaa on 15/5/11.
//  Copyright (c) 2015年 Easaa. All rights reserved.
//

#import "MagazineListTabView.h"

@implementation MagazineListTabView
{

    HXHttpRequest           *_httpRequest;              //发起请求
    HXHttpRequest           *_httpRequest_head;         //发起请求  ---(请求tabbleview 的headview)
    NSMutableArray      *_DataModel;
}




- (id)initWithFram: (CGRect)frame CategoryModel:(ZilneListDataModel *)model
{
    self = [super initWithFrame:frame];
    if (self)
    {
        
        self.dataSource =self;
        self.delegate =self;
        self.delaysContentTouches = NO;
        _DataModel = [[NSMutableArray alloc]init];
        self.zlinModel = model;
        
        [self RequestHeadlLinesAndHeadImageDataFantion];
        
        
        
        UIImageView  *veiwimage =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, Dev_ScreenWidth, Dev_ScreenHeight/2+60)];
        
        [veiwimage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.hellomommy.cn%@",model.Image]] placeholderImage:[UIImage imageNamed:@"bgzlin"]];
        self.tableHeaderView=veiwimage;
        
        

    }
    return self;
}




-(void)RequestHeadlLinesAndHeadImageDataFantion
{
  
    //列表请求  参数为 用户ID  、 用户账号
    NSDictionary* dicParams = [NSDictionary dictionaryWithObjectsAndKeys:
                               [XSZ_UICommon useridChangUaerdfLoginBoolString],                    @"user_id",
                               @"1",                    @"site_id",
                               [NSNumber numberWithInteger:[self.zlinModel.id_massge integerValue]],     @"id",
                               nil];
    
    
    if (_httpRequest == nil)
    {
        _httpRequest = [[HXHttpRequest alloc] init];
        _httpRequest.delegate = self;
        
        
        
    }
    [_httpRequest requestForParams:dicParams andMethod:YZ_ZINE_CATALOGUE andTag:1001];


}



#pragma mark - HXHttpRequestDelegate  代理

- (void)requestFinished:(NSString *)responseString andStatusCode:(int)statusCode andTag:(NSInteger)tag
{
    
    
    //停止刷新
    [self.legendHeader endRefreshing];
    [self.legendFooter endRefreshing];
    

    NSDictionary *dic = [[NSDictionary alloc]init];
    dic = [JsonUtil jsonToDic:responseString];
    
    if ([dic[@"data"] isEqual:[NSNull null]])
    {
        return;
    }
    
    NSString * strs = dic[@"data"];
    
    NSDictionary *dics =[JsonUtil jsonToDic:strs];
    
    NSArray *arryy =(NSArray *)dics;
    
    //NSLog(@"-----------> %@",arryy);
    //NSMutableArray *arryData = [[NSMutableArray alloc]init];
    
    for (NSDictionary *dicuu in arryy) {
        
        
        HeadZlineMassgeModel *cellmodel =[[HeadZlineMassgeModel alloc]initWithDataDic:dicuu];
        

        [_DataModel addObject:cellmodel];
        
    }
    
        
        [self reloadData];
        
        
//ZlineMassgeModel   HeadZlineMassgeModel
    
    
}


#pragma mark  HXHttpRequest - 请求代理，，错误代理
- (void)requestFailed:(NSError *)error andTag:(NSInteger)tag
{
    
    
    
    
    
}





#pragma arguments - mark  UITableViewDelegate
// 返回每组行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _DataModel.count;
}


//设置每行高度（每行高度可以不一样）
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    HeadZlineMassgeModel *cellmodel = [_DataModel objectAtIndex:indexPath.row];
    
    return 60+cellmodel.Articles.count*40+20;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  
    
    static  NSString  *CellIdentiferId = @"ZineModelCellID";
    //ContactModelCell  *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentiferId];
    //    if (cell == nil) {
    ////        NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"ActivityTableViewCell" owner:nil options:nil];
    ////        cell = [nibs lastObject];
    ////        cell.backgroundColor = [UIColor clearColor];
    //        cell  = [[ContactModelCell alloc]init];
    //
    //
    //    }
    
    ZineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentiferId];
    if (cell == nil)
    {
        
        cell = [[ZineTableViewCell alloc] initWithDataStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentiferId];
    }
    
    if(_DataModel.count<1)
    {
        return cell;
    }
    HeadZlineMassgeModel *cellmodel = [_DataModel objectAtIndex:indexPath.row];
    cell.HeadmodelArry =_DataModel;
    cell.headmdoelcount = indexPath.row;
    [cell creatCellView:cellmodel];
   
// cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.TableviewNavDelegat = self.TableviewNavDelegat;
   
    
    
    return cell;
    
}


#pragma mark   Tableview  点击事件代理
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
//    
//    [self.ListTableviewdelegate PushViewContorllerDataModel: [self.DataModel objectAtIndex:indexPath.row]];
    
    
}








@end

